package thread.lock;

public class YieldTest {
    public static int COUNT1 = 0;
    public static int COUNT2 = 0;
    public static void add1(){
        System.out.println(Thread.currentThread().getName()+":"+COUNT1++);
    }
    public static void add2(){
        System.out.println(Thread.currentThread().getName()+":"+COUNT2++);
    }

    public static void main(String[] args) {
        new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                Thread.yield();
                add1();
            }
        },"t1").start();

        new Thread(()->{
            for (int i = 0; i < 1000; i++) {
                add2();
            }
        },"t2").start();

    }

}
